<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>阻止事件冒泡和阻止事件默认行为</title>
</head>
<body>
    <div>
        <p>
            <a href="https://www.baidu.com">百度</a>
        </p>
        <input type="text">
        <input type="button" id="btn" value="按钮">
    </div>
    <script>
        document.body.onclick = function(){
            console.log("body");
        }
        document.querySelector("div").onclick = function(){
            console.log("div");
        }
        document.querySelector("p").onclick = function(e){
            console.log("p");
            e.stopPropagation();
        }
        document.querySelector("a").onclick = function(e){
            console.log("a");
            e.preventDefault();
        }
        document.querySelector("input").onkeypress = function(e){
            console.log(e.keyCode);
            if(e.keyCode < 48 || e.keyCode > 57){
                e.preventDefault();
            }
            // 

        }
        document.getElementById("btn").onclick = function(e){
            console.log("按钮按下");
            e.preventDefault();
        }
    </script>
</body>
</html>